package ControlLayer;

import java.sql.Date;
import java.util.ArrayList;

import DBLayer.*;
import ModelLayer.*;



public class CtrOfferLabour {
	
	DBOfferLabour dbOfferLabour;
	
	public CtrOfferLabour()
	{
		dbOfferLabour = new DBOfferLabour();
	}

	
	
	
	public ArrayList<OfferLabour> getAllOfferLabour()
	{
		return dbOfferLabour.getAllOfferLabours();
	}
	
	
	
	public OfferLabour findOfferLabour(int offerId) 
	{
		return dbOfferLabour.findOfferLabour(offerId);
	}	


	public OfferLabour findOfferLabourById(int offerLabourId) 
	{
		return dbOfferLabour.findOfferLabourById(offerLabourId);
	}	
	
	
	public int deleteOfferLabour(int offerLabourId)
	{
		return dbOfferLabour.deleteOfferLabour(offerLabourId);
	}
	
	public int deleteOfferLabourConnected(int offerId)
	{
		return dbOfferLabour.deleteOfferLabourConnected(offerId);
	}
	
	
	
	
	public int updateOfferLabour1(int offerId, int labourId, double price, int amount, String name, int offerLabourId)
	{
		OfferLabour offerLabour = new OfferLabour(price, amount, offerId, labourId, name, offerLabourId);
		return dbOfferLabour.updateOfferLabour(offerLabour);
	}
	
	public void insertNewOfferLabour(int offerId, int labourId, double price, int amount, String name, int offerLabourId)
    {    
     OfferLabour offerLabourObj = new OfferLabour();
     offerLabourObj.setOfferId(offerId);
     offerLabourObj.setLabourId(labourId);
     offerLabourObj.setLabourPrice(price);
     offerLabourObj.setLabourAmount(amount);
     offerLabourObj.setLabourName(name);
     offerLabourObj.setOfferLabourId(offerLabourId);
    
    

         try{
          DbConnection.startTransaction();
          
          DBOfferLabour dbOfferLabour = new DBOfferLabour();
          dbOfferLabour.insertOfferLabour(offerLabourObj);
          DbConnection.commitTransaction();
         }
         catch(Exception e)
         {
             DbConnection.rollbackTransaction();
         }
    }
	
}
